package com.axend.aerosense.home.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.axend.aerosense.common.util.DateUtil;
import com.axend.aerosense.home.entity.WardReportBean;
import com.axend.aerosense.home.R;
import com.zhpan.bannerview.BaseBannerAdapter;
import com.zhpan.bannerview.BaseViewHolder;

public class BannerReportAdapter extends BaseBannerAdapter<WardReportBean> {
    private Fragment fragment;
    private IReportsClick<WardReportBean> iReportsClick;

    public BannerReportAdapter(Fragment fragment, IReportsClick<WardReportBean> iReportsClick) {
        this.fragment = fragment;
        this.iReportsClick = iReportsClick;
    }

    @Override
    protected void bindData(BaseViewHolder<WardReportBean> holder, WardReportBean data, int position, int pageSize) {
//        View view = holder.itemView.findViewById(R.id.home_look_report);
        TextView tvWardName = holder.itemView.findViewById(R.id.home_ward_name);
        TextView tvLogTime = holder.itemView.findViewById(R.id.home_report_time);
        LinearLayout homeAdlReports = holder.itemView.findViewById(R.id.home_adl_reports);
        LinearLayout homeSleepReports = holder.itemView.findViewById(R.id.home_sleep_reports);

        tvWardName.setText(data.getReportName());
        String tmp = DateUtil.getStringDateMMddyyyyHHmm(data.getReportTime());
        tvLogTime.setText(tmp);

        if(!TextUtils.isEmpty(data.getAdlurl())){
            homeAdlReports.setVisibility(View.VISIBLE);
            homeAdlReports.setOnClickListener(v -> {
                if (null != iReportsClick){
                    iReportsClick.onAdlReportClick(data);
                }
            });
        }else {
            homeAdlReports.setVisibility(View.GONE);
        }

        if(!TextUtils.isEmpty(data.getSleepUrl())){
            homeSleepReports.setVisibility(View.VISIBLE);
            homeSleepReports.setOnClickListener(v -> {
                if (null != iReportsClick){
                    iReportsClick.onSleepReportClick(data);
                }
            });
        }else {
            homeSleepReports.setVisibility(View.GONE);
        }
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.home_banner_report_item;
    }

}
